fetcher: Explicitly join thread if it's not self
authorColin Walters <walters@verbum.org>
Sun, 24 Jul 2016 19:11:17 +0000 (15:11 -0400)
committerAtomic Bot <atomic-devel@projectatomic.io>
Thu, 28 Jul 2016 10:10:17 +0000 (10:10 +0000)
This fixes a valgrind leak; see [this StackOverflow thread](http://stackoverflow.com/questions/17642433/why-pthread-causes-a-memory-leak).

Closes: #410
Approved by: giuseppe

src/libostree/ostree-fetcher.c

index 865c7b765dfdfdb20cfab836349cb08ac61af4da..bde6ed9aa4bfd58e914d6b38e271c18f3bdf47af 100644 (file)
@@ -540,7 +540,14 @@ _ostree_fetcher_finalize (GObject *object)
 
   /* Terminate the session thread. */
   g_main_loop_quit (self->thread_closure->main_loop);
-  g_clear_pointer (&self->session_thread, g_thread_unref);
+  if (self->session_thread)
+    {
+      /* We need to explicitly synchronize to clean up TLS */
+      if (self->session_thread != g_thread_self ())
+        g_thread_join (self->session_thread);
+      else
+        g_clear_pointer (&self->session_thread, g_thread_unref);
+    }
   g_clear_pointer (&self->thread_closure, thread_closure_unref);
 
   G_OBJECT_CLASS (_ostree_fetcher_parent_class)->finalize (object);